package router

import (
	"github.com/astaxie/beego"
	"encoding/json"
)

type MainController struct {
	beego.Controller
}

func (this *MainController) Login() {
	this.TplName = "login.html"
}
func (this *MainController) Index() {
	this.TplName = "index.html"
}

func (this *MainController) Data() {
	a := map[string] string{}
	a["a"] = "sas"
	a["b"] = "sa2s"
	a["c"] = "sas3"
	bytes, _ := json.Marshal(a)
	this.Ctx.WriteString(string(bytes))
}

func (this *MainController) Logind() {
	this.SetSession("sessionState",true)
	//this.Ctx.WriteString("登录成功")
	this.Ctx.Redirect(302,"/index")
}

func init()  {
	beego.Router("/", &MainController{},"Get:Login")
	beego.Router("/login", &MainController{},"Get:Login")
	beego.Router("/index", &MainController{},"Get:Index")
	beego.Router("/data", &MainController{},"Post:Data")
	beego.Router("/login", &MainController{},"Post:Logind")
}